package binarySearch;

public class MySqrt {

    public int mySqrt(int x) {
        if(x == 0){
            return 0;
        }
        if(x == 1){
            return 1;
        }
        long l = 0;
        long r =  x/2 + 1;
        while(l < r){
            long mid = (l + r + 1) /2;
            if( mid * mid > x){
                r = mid -1;
            } else {
                l = mid;
            }
        }
        return (int)l;
    }
}
